<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>CIA402从会到会不会——PTP功能块实现 - 陈的错题集</title><meta name="Description" content="陈的错题集 - 个人笔记"><meta property="og:title" content="CIA402从会到会不会——PTP功能块实现" />
<meta property="og:description" content="经过对CIA402的介绍，再根据PLCOpen MontionControl的状态机，实现一套用于简单PTP控制的功能块。 状态机 如轴状态机图所" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://example.com/cia402_07ptpfunctionblock/" /><meta property="og:image" content="https://example.com/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2024-01-29T22:39:33+08:00" />
<meta property="article:modified_time" content="2024-01-29T22:39:33+08:00" /><meta property="og:site_name" content="陈的错题集" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://example.com/logo.png"/>

<meta name="twitter:title" content="CIA402从会到会不会——PTP功能块实现"/>
<meta name="twitter:description" content="经过对CIA402的介绍，再根据PLCOpen MontionControl的状态机，实现一套用于简单PTP控制的功能块。 状态机 如轴状态机图所"/>
<meta name="application-name" content="陈的错题集">
<meta name="apple-mobile-web-app-title" content="陈的错题集"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://example.com/cia402_07ptpfunctionblock/" /><link rel="prev" href="https://example.com/cia402_06homemode/" /><link rel="next" href="https://example.com/wpf_communitytoolkitmvvm/" /><link rel="stylesheet" href="/css/style.min.css"><link rel="preload" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/all.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
        <noscript><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/all.min.css"></noscript><link rel="preload" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.1/animate.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
        <noscript><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.1/animate.min.css"></noscript><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "CIA402从会到会不会——PTP功能块实现",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/example.com\/cia402_07ptpfunctionblock\/"
        },"image": ["https:\/\/example.com\/images\/Apple-Devices-Preview.png"],"genre": "posts","keywords": "cia402","wordcount":  785 ,
        "url": "https:\/\/example.com\/cia402_07ptpfunctionblock\/","datePublished": "2024-01-29T22:39:33+08:00","dateModified": "2024-01-29T22:39:33+08:00","publisher": {
            "@type": "Organization",
            "name": "xxxx","logo": "https:\/\/example.com\/images\/avatar.png"},"author": {
                "@type": "Person",
                "name": "Jacob Chen"
            },"description": ""
    }
    </script></head>
    <body data-header-desktop="fixed" data-header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="陈的错题集">💻陈的错题集</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 📜归档 </a><a class="menu-item" href="/tags/"> 🏷️标签 </a><a class="menu-item" href="/categories/"> 📂分类 </a><a class="menu-item" href="/about/"> ⭐关于 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder=" " id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
                </a></div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="陈的错题集">💻陈的错题集</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder=" " id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">📜归档</a><a class="menu-item" href="/tags/" title="">🏷️标签</a><a class="menu-item" href="/categories/" title="">📂分类</a><a class="menu-item" href="/about/" title="">⭐关于</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
            </a></div>
    </div>
</header><div class="search-dropdown desktop">
        <div id="search-dropdown-desktop"></div>
    </div>
    <div class="search-dropdown mobile">
        <div id="search-dropdown-mobile"></div>
    </div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animate__animated animate__flipInX">CIA402从会到会不会——PTP功能块实现</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel="author" class="author"><i class="fas fa-user-circle fa-fw" aria-hidden="true"></i>Jacob Chen</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/%E8%BF%90%E5%8A%A8%E6%8E%A7%E5%88%B6/"><i class="far fa-folder fa-fw" aria-hidden="true"></i>运动控制</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw" aria-hidden="true"></i>&nbsp;<time datetime="2024-01-29">2024-01-29</time>&nbsp;<i class="fas fa-pencil-alt fa-fw" aria-hidden="true"></i>&nbsp;约 785 字&nbsp;
                <i class="far fa-clock fa-fw" aria-hidden="true"></i>&nbsp;预计阅读 2 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  data-kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right" aria-hidden="true"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#状态机">状态机</a></li>
    <li><a href="#实现的简单ptp功能">实现的简单PTP功能</a></li>
    <li><a href="#使用案例">使用案例</a>
      <ul>
        <li><a href="#添加从站并自定义pdo数据">添加从站并自定义PDO数据</a></li>
        <li><a href="#pdo映射">PDO映射</a>
          <ul>
            <li><a href="#声明轴控变量">声明轴控变量</a></li>
            <li><a href="#pdo变量映射">PDO变量映射</a></li>
          </ul>
        </li>
        <li><a href="#功能块使用">功能块使用</a></li>
      </ul>
    </li>
    <li><a href="#功能块下载与导入">功能块下载与导入</a>
      <ul>
        <li><a href="#导入">导入</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><!-- # CIA402从会到会不会——PTP功能块实现 -->
<blockquote>
<p>经过对CIA402的介绍，再根据PLCOpen MontionControl的状态机，实现一套用于简单PTP控制的功能块。</p>
</blockquote>
<h2 id="状态机">状态机</h2>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-MotionControl%e7%8a%b6%e6%80%81%e6%9c%ba.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-MotionControl%e7%8a%b6%e6%80%81%e6%9c%ba.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-MotionControl%e7%8a%b6%e6%80%81%e6%9c%ba.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-MotionControl%e7%8a%b6%e6%80%81%e6%9c%ba.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-MotionControl状态机.png"
        title="轴状态机图" /></p>
<p>如轴状态机图所示，所有轴控相关的功能均受状态机的影响。不同状态机下，可以执行不同的功能块。</p>
<h2 id="实现的简单ptp功能">实现的简单PTP功能</h2>
<ul>
<li><strong>功能块</strong>
<ul>
<li><strong>DFB_AxisRefConfig</strong>：用于配置轴参数（如单位脉冲、导程等）、判断轴状态（如报警、操作模式等）的功能块，需要Enable为True时才可执行其他功能块。</li>
<li><strong>DFB_Power</strong>：使能功能块。</li>
<li><strong>DFB_Reset</strong>：复位功能块。</li>
<li><strong>DFB_Stop</strong>：停止功能块。</li>
<li><strong>DFB_Home</strong>：回零功能块。使用HM模式实现。</li>
<li><strong>DFB_Jog</strong>：点动功能块。使用PV模式实现。</li>
<li><strong>DFB_MoveAbsolute</strong>：绝对定位功能块。使用PP模式实现。</li>
<li><strong>DFB_MoveRelative</strong>：相对定位功能块。使用PP模式实现。</li>
</ul>
</li>
<li><strong>自定义数据类型</strong>
<ul>
<li><strong>ST_Axis_Ref</strong>：轴结构体。包括轴控所需要的信息。</li>
<li><strong>ST_Axis_PdoIn</strong>：PDO输入结构体。用于从站PDO映射的结构体变量（如状态字、实际位置等）。</li>
<li><strong>ST_Axis_PdoOut</strong>：PDO输出结构体。用于从站PDO映射的结构体变量（如控制字、目标位置等）。</li>
<li><strong>E_Axis_State</strong>：轴状态机枚举。用于判断当前轴处于什么状态。</li>
<li><strong>E_Axis_OperationMode</strong>：操作模式枚举。包括PP、PV、PT、HM、CSP、CSV、CST共7种模式。</li>
<li><strong>E_Axis_Error</strong>：错误枚举。用于指示功能块执行过程中的错误。</li>
</ul>
</li>
</ul>
<h2 id="使用案例">使用案例</h2>
<p>以台达AX系列PLC（Codesys系统）+台达A2-E伺服驱动器为例，介绍该功能块使用流程</p>
<h3 id="添加从站并自定义pdo数据">添加从站并自定义PDO数据</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e6%b7%bb%e5%8a%a0%e4%bb%8e%e7%ab%99.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e6%b7%bb%e5%8a%a0%e4%bb%8e%e7%ab%99.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e6%b7%bb%e5%8a%a0%e4%bb%8e%e7%ab%99.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e6%b7%bb%e5%8a%a0%e4%bb%8e%e7%ab%99.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-添加从站.png"
        title="自定义PDO数据" /></p>
<p>按照<strong>ST_Axis_PdoIn</strong>、<strong>ST_Axis_PdoOut</strong>结构体所要求的数据，编辑PDO数据。</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO%e6%95%b0%e6%8d%ae.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO%e6%95%b0%e6%8d%ae.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO%e6%95%b0%e6%8d%ae.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO%e6%95%b0%e6%8d%ae.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO数据.png"
        title="PDO数据" /></p>
<h3 id="pdo映射">PDO映射</h3>
<h4 id="声明轴控变量">声明轴控变量</h4>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e8%bd%b4%e6%8e%a7%e5%8f%98%e9%87%8f.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e8%bd%b4%e6%8e%a7%e5%8f%98%e9%87%8f.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e8%bd%b4%e6%8e%a7%e5%8f%98%e9%87%8f.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e8%bd%b4%e6%8e%a7%e5%8f%98%e9%87%8f.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-轴控变量.png"
        title="轴控变量" /></p>
<h4 id="pdo变量映射">PDO变量映射</h4>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO%e6%98%a0%e5%b0%84.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO%e6%98%a0%e5%b0%84.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO%e6%98%a0%e5%b0%84.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO%e6%98%a0%e5%b0%84.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-PDO映射.png"
        title="PDO映射" /></p>
<h3 id="功能块使用">功能块使用</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e5%8a%9f%e8%83%bd%e5%9d%97%e8%b0%83%e7%94%a8.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e5%8a%9f%e8%83%bd%e5%9d%97%e8%b0%83%e7%94%a8.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e5%8a%9f%e8%83%bd%e5%9d%97%e8%b0%83%e7%94%a8.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e5%8a%9f%e8%83%bd%e5%9d%97%e8%b0%83%e7%94%a8.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-功能块调用.png"
        title="功能块使用" /></p>
<h2 id="功能块下载与导入">功能块下载与导入</h2>
<p>下载链接: <a href="https://pan.baidu.com/s/1IpSh8x4EX_nsPLBihkEtlg?pwd=zegy" target="_blank" rel="noopener noreffer ">https://pan.baidu.com/s/1IpSh8x4EX_nsPLBihkEtlg?pwd=zegy</a> 提取码: zegy</p>
<h3 id="导入">导入</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e5%8a%9f%e8%83%bd%e5%9d%97%e5%af%bc%e5%85%a5.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e5%8a%9f%e8%83%bd%e5%9d%97%e5%af%bc%e5%85%a5.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e5%8a%9f%e8%83%bd%e5%9d%97%e5%af%bc%e5%85%a5.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-%e5%8a%9f%e8%83%bd%e5%9d%97%e5%af%bc%e5%85%a5.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Cia402-PTP-功能块导入.png"
        title="功能块导入" /></p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2024-01-29</span>
            </div></div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/cia402_07ptpfunctionblock/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw" aria-hidden="true"></i>&nbsp;<a href="/tags/cia402/">cia402</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/cia402_06homemode/" class="prev" rel="prev" title="CIA402从会到不会——原点复归模式（6）"><i class="fas fa-angle-left fa-fw" aria-hidden="true"></i>CIA402从会到不会——原点复归模式（6）</a>
            <a href="/wpf_communitytoolkitmvvm/" class="next" rel="next" title="MVVM框架——CommunityToolkit.Mvvm">MVVM框架——CommunityToolkit.Mvvm<i class="fas fa-angle-right fa-fw" aria-hidden="true"></i></a></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.115.4">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.11"><i class="far fa-kiss-wink-heart fa-fw" aria-hidden="true"></i> LoveIt</a>
                </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw" aria-hidden="true"></i><span itemprop="copyrightYear">2023 - 2024</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">Jacob Chen</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw" aria-hidden="true"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw" aria-hidden="true"></i>
            </a>
        </div><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/autocomplete.js@0.38.1/dist/autocomplete.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lunr@2.3.9/lunr.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lazysizes@5.3.2/lazysizes.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":50},"comment":{},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":30,"type":"lunr"}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
